﻿Imports BUS
Imports DTO
Public Class frmBaoCaoThongKeTinhHinhChoMuonSachTheoTheLoai : Inherits DevComponents.DotNetBar.Office2007Form
    Private m_nhanvien As CNhanVienDTO
    Public Property NhanVien() As CNhanVienDTO
        Get
            Return m_nhanvien
        End Get
        Set(ByVal value As CNhanVienDTO)
            m_nhanvien = value
        End Set
    End Property
    Public Function ConvertFromListToDataSet(ByVal ltheloai As List(Of CTheLoaiSachDTO)) As DataTable
        Dim tb As New DataTable()
        tb.Columns.Add("TenTheLoai", Type.GetType("System.String"))
        tb.Columns.Add("SoLuotMuon", Type.GetType("System.Int32"))
        Dim newrow As DataRow
        For Each item As CTheLoaiSachDTO In ltheloai
            newrow = tb.NewRow()
            newrow("TenTheLoai") = New CTheLoaiSachBUS().LayTenTheLoaiSachTheoMa(item.Ma)
            newrow("SoLuotMuon") = item.SoLuotMuon
            tb.Rows.Add(newrow)
        Next
        Return tb
    End Function

    Private isdanhdau = False
    Private Sub frmBaoCaoThongKeTinhHinhChoMuonSachTheoTheLoai_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For i As Integer = 2010 To 2100
            ComboBoxExNam.Items.Add(i)
            If (i = DateTime.Now.Year) Then
                ComboBoxExNam.SelectedIndex = i - 2010
            End If
        Next

        For i As Integer = 1 To 12
            ComboBoxExThang.Items.Add(i)
            If (i = DateTime.Now.Month) Then
                ComboBoxExThang.SelectedIndex = i - 1
            End If
        Next

        isdanhdau = True
        Reload()
    End Sub

    Private Sub Reload()
        Dim view As New rptBaoCaoThongKeTinhHinhChoMuonSachTheoTheLoai()
        view.SetDataSource(ConvertFromListToDataSet(New CTheLoaiSachBUS().MuonSachTheoTheLoai(ComboBoxExThang.SelectedItem, ComboBoxExNam.SelectedItem)))
        view.SetParameterValue("Thang", ComboBoxExThang.SelectedItem)
        view.SetParameterValue("Nam", ComboBoxExNam.SelectedItem)
        view.SetParameterValue("NguoiLap", m_nhanvien.HoTen)
        CrystalReportViewer1.ReportSource = view

        CrystalReportViewer1.Refresh()
    End Sub
    Private Sub ComboBoxExThang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxExThang.SelectedIndexChanged

        If isdanhdau Then
            Reload()
        End If


    End Sub

    Private Sub ComboBoxExNam_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxExNam.SelectedIndexChanged

        If isdanhdau Then
            Reload()
        End If


    End Sub
End Class